import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

import { useCounterStore } from '@/stores/counter'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'Login',
      component: () => import('../views/LoginView.vue'),
    },
    {
      path: '/Demo',
      name: 'Demo',
      component: () => import('../views/DemoView.vue'),
    },
    {
      path: '/Home',
      name: 'Home',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/HomeView.vue'),
      children: [
        {
          path: '/Introduction',
          name: 'Introduction',
          component: () => import('@/views/IntroductionView.vue'),
        },
        {
          path: '/Scheduling',
          name: 'Scheduling',
          component: () => import('@/views/Schedulings/SchedulingView.vue'),
        },
        {
          path: '/BOMlist',
          name: 'BOMlist',
          component: () => import('@/views/BOM/BOMlistView.vue'),
        },
        {
          path: '/BOMdetails',
          name: 'BOMdetails',
          component: () => import('@/views/BOM/BOMdetailsView.vue'),
        },
        {
          path: '/MakestepView',
          name: 'MakestepView',
          component: () => import('@/views/工艺工序/MakestepView.vue'),
        },
        {
          path: '/MakestepdetailsView',
          name: 'Makestepdetails',
          component: () => import('@/views/工艺工序/MakestepdetailsView.vue'),
        },
        {
          path: '/Workbench',
          name: 'Workbench',
          component: () => import('@/views/Workbenchs/WorkbenchView.vue'),
        },
        {
          path: '/Userinfo',
          name: 'Userinfo',
          component: () => import('@/views/Users/UserInfoView.vue'), // 修正此处
        },
        {
          path: '/Qualitylist',
          name: 'Qualitylist',
          component: () => import('@/views/Quality/QualitylistView.vue'),
        },
        {
          path: '/Passwork',
          name: 'Passwork',
          component: () => import('@/views/Users/PassworkView.vue'),
        },
        {
          path: '/addquality',
          name: 'addquality',
          component: () => import('@/views/Quality/AddQuality.vue'),
        },
        {
          path: '/QuseryUser',
          name: 'QuseryUser',
          component: () => import('@/views/Users/QueryUserView.vue'), // 修正此处
        },
        {
          path: '/RoleManagement',
          name: 'RoleManagement',
          component: () => import('@/views/Users/RoleManagementView.vue'),
        },
        {
          path: '/PermissionManagement',
          name: 'PermissionManagement',
          component: () => import('@/views/Users/PermissionManagementView.vue'),
        },
        {
          path: '/DepartmentManagement',
          name: 'DepartmentManagement',
          component: () => import('@/views/Users/DepartmentManagementView.vue'),
        },
        {
          path: '/qualitywork',
          name: 'qualitywork',
          component: () => import('@/views/Quality/Qualitydetail_work.vue'),
        },
        {
          path: '/qualityorder',
          name: 'qualityorder',
          component: () => import('@/views/Quality/Qualitydetail_order.vue'),
        },
        {
          path: '/Laneway',
          name: 'Laneway',
          component: () => import('@/views/Laneway/LanewayView.vue'),
        },
      ],
    },
  ],
})
// router.beforeEach((to, from, next) => {
//   const store = useCounterStore()
//   const isAuthenticated = store.userinfo.routerstate
//   if (to.name !== 'Login' && isAuthenticated) next({ name: 'Login' })
//   else next()
// })

export default router
